<?php
/**
 * @author Akulov Denis
 * @since 03.07.2011
 */
class K_Carcass {

    private $content = '';


    private $nodes = array();


    const MAIN_REQUEST = '<!--@ MAIN REQUEST -->';


    public function __construct($name, K_Config $objConfig) {
        $fn = $objConfig->getConfig('PROJECT_PATH').'/carcasses/'.strtolower($name).'.html';
        if (!is_file($fn)) {
            $fn = $objConfig->getConfig('PROJECT_PATH').'/carcasses/';
            $fn .= $objConfig->getConfig('DEFAULT_CARCASS').'.html';
        }

        $this->content = file_get_contents($fn);
        preg_match_all('/<!--@.*\s-->/iU', $this->content, $this->nodes);
        $this->nodes = $this->nodes[0];
    }


    public function getNodes () {
        return $this->nodes;
    }


    public function render ($arSource) {
        foreach ($arSource as $k => $v) {
            $this->content = str_replace($k, $v, $this->content);
        }

        return $this->content;
    }

}